var type = '';
var icloudNo = "";
var jName = getCookie('Jname');

//我的权限数组
var arrayTitle = new Array;

	$(document).ready(function() {
		findMyCatalogue();
		init(1,"","");
	});

	//默认加载  
	function init(pageNo, type, phone) {
		//获取用户信息列表
		$("#thislist").html("");
		$.ajax({
			url: urlcore + "/api/appFeedback/selectAllFeedBackList?current=" + pageNo + "&type=" + type + "&phone=" + phone,
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success: function(data) {
				if(data.success == true) {
					//i表示在data中的索引位置，n表示包含的信息的对象
					$.each(data.data.records, function(i, n) {
						var thislist = "";
						var id = n.id;
						var real_name = n.user.realName;
						var phone = n.phone;
						var img_url = n.imgUrl;
						
						var imgStr1 = '';
						if(n.imgUrl != null && n.imgUrl != '') {
						var imgarr = n.imgUrl.split("***");
						$.each(imgarr, function(index, value) {
					 	imgStr1="<img style=\"padding: 5px 5px 5px 5px;\" width=\"45px\" height=\"45px\" src=" + value + ">" 
							});
						}	
						
						var gmt_datetime = n.gmtDatetime;
						var upt_datetime = n.uptDatetime;
						var type;
						if(n.type == 1) {
							type = "认证";
						} else if(n.type == 2) {
							type = "借款";
						} else if(n.type == 3) {
							type = "还款";
						} else if(n.type == 4) {
							type = "体验与界面";
						} else {
							type = "其他";
						}
						
						
						thislist += '<tr>' +
							'<td class="footable-visible">' + id + '</td>' +
							'<td class="footable-visible">' + real_name + '</td>' +
							'<td class="footable-visible">' + phone + '</td>' +
							'<td class="footable-visible">'+ imgStr1 +'</td>' +
							'<td class="footable-visible">' + gmt_datetime + '</td>' +
							'<td class="footable-visible">' + type + '</td>' +
							'<td class="footable-visible footable-last-column">' +
								" <a hidden=\"hidden\"  name=\"详细\" class=\"btn btn-success btn-xs\" href=\"appfeedback_detail.html?id="+ id +"\"> 详细</a>\n"
							'</td>' +
							'</tr>';
						$('#thislist').append(thislist);
						$('#thiscount').html(data.data.total);
					});
					$.each(arrayTitle, function(i,k) {
						$('a[name="'+k+'"]').attr("hidden",false).attr("class","btn btn-primary btn-xs");
						$('a[data="'+k+'"]').attr("class","btn btn-sm btn-primary");
					});
					$("#pager").pager({
	                    pagenumber: pageNo,
	                    pagecount: data.data.pages,
	                    totalcount: data.data.total,
	                    buttonClickCallback: PageClick
	                });
					$.each(arrayTitle, function(i, k) {
						$('a[name="' + k + '"]').attr("hidden", false).attr("class", "btn btn-primary btn-xs");
						$('a[data="topButton"]').attr("class", "btn btn-sm btn-primary");
					});
					$('#thiscount').text(data.data.total);
				} else if(data.code == 'OVERTIME') {
					var thisUrl = window.location.href;
					if(thisUrl.indexOf('login.html') <= -1) {
						top.window.location.href = "login.html";
					}

				} else {
					if(data.msg != '空数据') {
						alert(data.msg)
					} else {
						$('#thiscount').text(0);
					}
				}
			},
			error: function() {
				/* Act on the event */
				alert("error");
			}
		});
		//回调函数  
	PageClick = function(pageclickednumber) {
		var type = $('#type').val();
		var phone = $("#phone").val();
		init(pageclickednumber,type, phone);
	}
	}

	
/**
 * 查询
 */

	function searchList() {
		var type = $('#type').val();
		var phone = $("#phone").val();
		init(1,type,phone);
	}
	
function findMyCatalogue(){
	$.ajax({
		url: urlcore + "/api/roleThirdCatalogue/findAllByUser?secondTitle="+jName,
		type: "GET",
		dataType: 'json',
		async: false,
		contentType: "application/json;charset=utf-8",
		success:function(data){
		if (data.success == true) {
			$.each(data.data, function(i,n) {
				arrayTitle.push(n.thirdCatalogue.title);
			});
		} else {
			alert(data.msg);
		}

		},
		error:function() {
			alert("error");
		}
	});
}